package br.ufrj.dcc.comp2.musica.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;
import javax.swing.JTable;

import br.ufrj.dcc.comp2.musica.controle.SolicitarInscricao;
import br.ufrj.dcc.comp2.musica.vista.PainelSolicitarIncricao;
import br.ufrj.dcc.comp2.musica.vista.ScrollPaneTabelaDisciplinasDisponiveis;

public class ListenerSolicitarInscricao implements ActionListener {
	private PainelSolicitarIncricao painel;
	ScrollPaneTabelaDisciplinasDisponiveis scrollPanes;
	JTable tabela;

	public ListenerSolicitarInscricao(
			ScrollPaneTabelaDisciplinasDisponiveis scrollPanes,
			PainelSolicitarIncricao painel) {
		this.scrollPanes = scrollPanes;
		tabela = scrollPanes.getTabelaListaDisciplinasDisponiveis();
		this.painel = painel;
	}

	public void actionPerformed(ActionEvent evento) {
		try {
			tabela.getValueAt(tabela.getSelectedRow(), 1);
		} catch (ArrayIndexOutOfBoundsException e) {
			JOptionPane.showMessageDialog(null,
					"Nenhuma disciplina foi selecionada", "Erro",
					JOptionPane.ERROR_MESSAGE);
			return;
		}
		painel.getControleCardLayout().setCard("Solicitar Desistencia");
		new SolicitarInscricao(tabela.getValueAt(tabela.getSelectedRow(), 1));
		painel.getControleCardLayout().setUltimoPainel("Gerenciar Inscricoes");

	}

}
